{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b18c9bde-ac54-41a3-8c35-6106c79a7a01",
   "metadata": {},
   "outputs": [],
   "source": [
    "#计算阶乘\n",
    "n=int(input(\"输入一个正整数：\"))\n",
    "def aaa(n):\n",
    "    if n < 0:\n",
    "        return \"输入必须是非负整数\" \n",
    "    elif n == 0 or n == 1:\n",
    "        return 1\n",
    "    else:\n",
    "        result = 1\n",
    "        for i in range(1, n + 1):\n",
    "            result *= i\n",
    "        return result\n",
    "print(aaa(n))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2fcf8b2-09e3-4252-9984-f27137cd7f3b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#判断素数\n",
    "n=int(input(\"输入一个正整数：\"))\n",
    "def bbb(n):\n",
    "    if n<=3:\n",
    "        return True\n",
    "    if n%2==0:\n",
    "        return False\n",
    "    for i in range(3,int(n**0.5)+1,2):\n",
    "        if n%i==0:\n",
    "           return False\n",
    "    return True \n",
    "result=\"是素数\"if bbb(n) else \"不是素数\"\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e1fc269d-8e40-4680-ae73-40da066c7250",
   "metadata": {},
   "outputs": [],
   "source": [
    "#反转字符串\n",
    "n=input(\"请输入要反转的字符串:\")\n",
    "def reverse(n):\n",
    "    return n[::-1]\n",
    "print(f\"反转结果为：'{reverse(n)}'\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d61f491-166b-4500-acaa-feb61697f43f",
   "metadata": {},
   "outputs": [],
   "source": [
    "#斐波那契数列\n",
    "n = int(input(\"请输入你想生成的项数(注意为正整数): \"))\n",
    "def ccc(n):\n",
    "    if n == 1:\n",
    "        return [0]\n",
    "    if n == 2:\n",
    "        return [0, 1]\n",
    "    start = [0, 1]\n",
    "    for i in range(2, n):\n",
    "        following = start[i-1] + start[i-2]\n",
    "        start.append(following)\n",
    "    return start\n",
    "result = ccc(n)\n",
    "print(f\"前{n}项数列为：{result}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45a60ee9-f6b9-4894-a7e4-1b08fd1f839d",
   "metadata": {},
   "outputs": [],
   "source": [
    "#找出最大值\n",
    "def mmmax(list):\n",
    "    if not list:\n",
    "        return None\n",
    "    maxxx = list[0] \n",
    "    for num in list:\n",
    "        if num > maxxx:\n",
    "            maxxx = num\n",
    "    return maxxx\n",
    "anylist =input(\"请输入数字列表（用空格分隔):\")\n",
    "numbers = [float(x) for x in anylist.split()]\n",
    "mmmaxxx= mmmax(numbers)\n",
    "print(f\"列表中的最大值: {mmmaxxx}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c5dc77d-a655-4376-9ca9-1bfb801353fa",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
